<template>
    <div class="head">
        <div class="head-left">
            <div class="col-md-1">
            <span style="cursor: pointer"><i class="fa fa-navicon"></i></span>
            </div>
            <div class="col-md-11">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>活动管理</el-breadcrumb-item>
                <el-breadcrumb-item>活动列表</el-breadcrumb-item>
                <el-breadcrumb-item>活动详情</el-breadcrumb-item>
            </el-breadcrumb>
            </div>
        </div>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            <i class="fa fa-user"></i>{{admin.name}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">退出</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                admin: {
                    id: 0,
                    name: '',
                    token: '',
                }
            };
        },
        methods: {
            handleCommand(command) {//退出框
                if (command == 1){
                    this.logout();
                }
            },
            checkLogin: function () {//检查登陆状态
                var _this = this;
                if (!_this.$cookie.get('token')){
                    _this.$router.push({path: '/admin/login'});
                }
            },
            logout: function (){//退出登陆
                var _this = this;
                console.log(_this.$cookie.get('token'));
                _this.$cookie.delete('admin.id');
                _this.$cookie.delete('admin.name');
                _this.$cookie.delete('token');
                _this.$router.push({path: '/admin/login'});
            },
        },
        mounted(){
            this.admin.id = this.$cookie.get('admin.id');
            this.admin.name = this.$cookie.get('admin.name');
            this.admin.token = this.$cookie.get('token');
            this.checkLogin();
            //api token传递
            axios.defaults.headers.common['Authorization'] = 'Bearer '+this.$cookie.get('token');
            axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        },
    }
</script>
